<html>
<head><meta charset="utf-8"><title>slow first query · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html">slow first query</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="188258217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188258217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188258217">(Feb 14 2020 at 23:46)</a>:</h4>
<p>I'm not sure if this is expected, but even on relatively small projects (e.g., a single <a href="http://lib.rs" target="_blank" title="http://lib.rs">lib.rs</a> with ~200 lines), when I first open a file in vim, the server pretty much instantaneously prints "workspace loaded, 12 rust packages". Then, when I use "go to definition" on anything, the server will jump to 100% CPU for maybe 2-3 seconds before responding.</p>
<p>On larger projects (e.g., rustc) that 2-3 seconds is probably more like 15 seconds, though I haven't measured. Certainly non-instantaneous. This means that my workflow in pretty much any coding session is to open vim, then go to some random line in a file, and "goto definition" and wait. After the first time I've done this, future queries are pretty much instantaneous -- but waiting for the first time is annoying.</p>
<p>I don't know whether I should file a bug. I guess the behavior I would have expected is to provide some way to say "please eagerly compute things in the background" -- most of the time, I'll only run a query after dozens of seconds have passed, so I don't need instantaneous feedback as soon as my editor opens... but I would prefer that I don't have to wait once I do decide to run a query.</p>
<p>One considerations is that in my case, at least, I don't care at all about battery/CPU usage/memory usage pretty much, because I'm running rust analyzer on a remote server (where I also run rustc and cargo), whereas my editor is local (on my laptop). That server has enough CPU cores and so forth that I'm not worried about rust analyzer doing work up front.</p>
<p>Happy to provide more details -- this is probably long enough already :)</p>



<a name="188258478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188258478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188258478">(Feb 14 2020 at 23:49)</a>:</h4>
<p>Yeah, this is a known issue: <a href="https://github.com/rust-analyzer/rust-analyzer/issues/1650" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/issues/1650">https://github.com/rust-analyzer/rust-analyzer/issues/1650</a></p>



<a name="188258582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188258582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188258582">(Feb 14 2020 at 23:51)</a>:</h4>
<p>The fundamental fix here is to implement on-disk persistence, so that everything can be cached and quickly loaded from disk.</p>
<p>However, we probably should prioritize a short-term remedy: eagerly "prime" freshly opened files, and parallelize the analysis</p>



<a name="188264878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188264878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188264878">(Feb 15 2020 at 02:14)</a>:</h4>
<p>Yes, to be clear, I'd be more than happy with doing lots of (potentially unnecessary) work at startup. Disk space is actually at more of a premium :)</p>



<a name="188267086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188267086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188267086">(Feb 15 2020 at 03:31)</a>:</h4>
<p>Thanks for the feedback though, that issue was an interesting read. I'll have to take a look at the Cargo.lock vs toml thing at least.</p>



<a name="188289880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188289880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188289880">(Feb 15 2020 at 16:38)</a>:</h4>
<p>Can we notify the user through progress notifications on the first slow query while everything is 'warming up' so they at least know that something is going on?</p>



<a name="188300595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188300595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188300595">(Feb 15 2020 at 22:05)</a>:</h4>
<p>We can, but I do feel that there's some low hanging fruit to make it actually faster that we should pick first. Like, an extremely basic thing to do would be to collect profile traces for this case and see if we do something stupid.</p>



<a name="188332605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188332605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188332605">(Feb 16 2020 at 17:32)</a>:</h4>
<p>Pushed a bench harness for goto-def specifically: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/3172" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/pull/3172">https://github.com/rust-analyzer/rust-analyzer/pull/3172</a></p>
<p>Here's a run for one of my projects, haven't investigated this yet</p>
<p><a href="https://gist.github.com/matklad/1812e96746e1d2befa5858da0cc888c4" target="_blank" title="https://gist.github.com/matklad/1812e96746e1d2befa5858da0cc888c4">https://gist.github.com/matklad/1812e96746e1d2befa5858da0cc888c4</a></p>



<a name="188333374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188333374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188333374">(Feb 16 2020 at 17:58)</a>:</h4>
<p>Looked a little bit and found interesting high-level bit we should optimize. A lot of time is spend collecting the impls. We need to collect all impls eagarly for trait solving, that’s how it works. However, our code for impls is lazy: we process each imple one by one, and, I think, we also look into impls bodies for that.</p>
<p>I think we need to change this to store impl headers (trait and type name, but probably not generics and where clauses) inside modules in crate def map, and only compute impl bodies lazily. Cc <span class="user-mention" data-user-id="129457">@Florian Diebold</span> , this looks like a fun find.</p>



<a name="188368255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188368255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> std::Veetaha <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188368255">(Feb 17 2020 at 10:46)</a>:</h4>
<p>(deleted)</p>



<a name="188981046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188981046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188981046">(Feb 25 2020 at 00:31)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> what exactly are you using with <code>vim</code>? I think there are many implementations of LSP for vim, I wonder if this somehow relates to this as well...</p>



<a name="188981098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188981098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188981098">(Feb 25 2020 at 00:32)</a>:</h4>
<p>ah, coc with vim 8 I thnk</p>



<a name="188981903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188981903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188981903">(Feb 25 2020 at 00:48)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> in theory I can try to run some experiments or so if it would be helpful</p>



<a name="188986738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188986738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> qmx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188986738">(Feb 25 2020 at 02:36)</a>:</h4>
<p>likewise I'm running coc with vim 8 too</p>



<a name="188986739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/188986739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> qmx <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#188986739">(Feb 25 2020 at 02:36)</a>:</h4>
<p>happy to do some debugging</p>



<a name="190200862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/slow%20first%20query/near/190200862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/slow.20first.20query.html#190200862">(Mar 10 2020 at 17:28)</a>:</h4>
<p>Status update here: in the recent update, we forecfully initiate analysis of opened files after workspace is loaded. It's not the super correct logic, but it shoudl help. In particular, one problem is that, if you modifiy a file during initial analysis, it won't be resceduled. </p>
<p>Low-hanging fruit about lazy impls turned out to be quite a yak shave: <a href="https://github.com/rust-analyzer/rust-analyzer/issues/3485" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/issues/3485">https://github.com/rust-analyzer/rust-analyzer/issues/3485</a><br>
I've also did a quick experiement with parallelization, but it was blocked by the same yak shave: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/3529" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/pull/3529">https://github.com/rust-analyzer/rust-analyzer/pull/3529</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>